﻿@using ETD.Common.Extension;
@using ETD.WebOrganization.Libs.Helper;
@using ETD.WinClient.Config;
@using ETD.Domain.EnumModels;
@using ETD.Domain.WebModels;
@using ETD.Common;
@model ETD.WebOrganization.Areas.Web.Models.IncomeEveryDayListModel
@{
    var incomeEveryDayList = Model.IncomeEveryDayList;
}
<style>

</style>
<div id="contentContainer">
    <div class="weui-cells__title">收益明细</div>
    <div class="weui-cells">
        <template>
            <a class="weui-cell weui-cell_access" v-for="(item, index) in itemList " v-on:click="onItemLinkClick(item)">
                <div class="weui-cell__bd">
                    <p>{{toYmdTime(item.IncomeDate)}}</p>
                </div>
                <div class="weui-cell__ft">￥{{decimalF2(item.Income)}}</div>
            </a>
            <div class="weui-loadmore" v-show="loading" style="margin-bottom:100px;">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">{{loadingText}}</span>
            </div>
            @*没有更多数据后，占位符，因为这里有一个添加按钮，占走了很多高度*@
            <div class="no-more-data-placehoder" v-show="!loading" style="margin-bottom:100px;">
            </div>
        </template>
    </div>

</div>
@section ScriptSection{
    <script>
        new Vue({
            el: '#contentContainer',
            data: {
                itemList: [],
                page: 0,
                hasMore: true,
                loading: false,
                loadingText: '向上滑动加载更多...'
            },
            created () {
                let self = this;
                this.getItemList();
                this.scrollBottom();
            }
            ,
            mounted () {
                // 添加滚动事件，检测滚动到页面底部
                //window.addEventListener('scroll', this.scrollBottom)
            },
            methods: {
                scrollBottom: function () {
                    let self = this;
                    var baseVue = new BaseVue();
                    baseVue.scrollBottom(self);
                },
                onItemLinkClick: function (item) {
                    window.location = "@Url.ActionTS("IncomeEveryDayDetailList","Financial")&incomeEveryDayID=" + item.IncomeEveryDayID;
                },
                decimalF2: function (num) {
                    return StringHelper.decimalF2(num);
                },
                toYmdhmsTime: function (time) {
                    return TimeHelper.ymdhmsTime(time);
                },
                toYmdTime: function (time) {
                    return TimeHelper.ymdTime(time);
                },
                getItemList: function () {
                    let self = this;
                    var organizationID = WinHelper.getUrlParam("organizationID");
                    var url = '@Url.Action("FindIncomeEveryDayList", "Financial")';
                    url = WinHelper.urlWrap(url);
                    var paras = {};
                    paras.OrganizationID = organizationID;
                    paras.CurrentPageIndex = self.page;
                    showCommonLoading();
                    // 获取今日新闻
                    axios.post(url, paras)
                      .then((res) => {
                          hideCommonLoading();
                          console.log(res.data);
                          this.bindItemList(res.data);
                      });
                },
                bindItemList: function (data) {
                    let self = this;
                    $.each(data.Data.IncomeEveryDayList, function (i, item) {
                        self.itemList.push(item);
                    });

                    self.loadingText = '向上滑动加载更多...'
                    if (self.itemList.length >= data.TotalCount) {
                        self.loadingText = "没有更多数据了...";
                        self.hasMore = false;
                        self.loading = false;
                    } else {
                        self.hasMore = true;
                    }
                }
            }
        })
    </script>
}